#include "mypushbutton.h"

MyPushButton::MyPushButton(QWidget *parent) : QPushButton(parent)
{

}

MyPushButton::MyPushButton(QString NormalImg,QString PressImg){
    NormalImgPath=NormalImg;
    PressImgPath=PressImg;
    //创建图片对象
    QPixmap pix;
    bool ret = pix.load(NormalImgPath);
    if(!ret){
        qDebug()<<NormalImgPath<<"图片加载失败";
    }
    //按钮大小设置为图片大小
    this->setFixedSize(pix.width(),pix.height());
    //设置边框为无边框
    setStyleSheet("QPushButton{border:0px};");
    setIcon(pix);
    setIconSize(QSize(pix.width(),pix.height()));
}

void MyPushButton::zoom(){
    //创建动画对象
    QPropertyAnimation *animation=new QPropertyAnimation(this,"geometry");
    //设置时间间隔，单位毫秒
    animation->setDuration(200);

    //向下弹跳
    //创建起始位置
    animation->setStartValue(QRect(this->x(),this->y(),this->width(),this->height()));
    //创建结束位置
    animation->setEndValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    //向上弹跳
    //创建起始位置
    animation->setStartValue(QRect(this->x(),this->y()+10,this->width(),this->height()));
    //创建结束位置
    animation->setEndValue(QRect(this->x(),this->y(),this->width(),this->height()));

    //设置缓和曲线，QEasingCurve::OutBounce 为弹跳效果
    animation->setEasingCurve(QEasingCurve::OutBounce);
    //开始执行动画
    animation->start();

}

//重写鼠标按压事件
//void MyPushButton::mousePressEvent(QMouseEvent *e){
//    QPixmap pix;
//    bool ret = pix.load(PressImgPath);
//    if(!ret){
//        qDebug()<<PressImgPath<<"图片加载失败";
//    }


//}
////重写鼠标释放事件
//void MyPushButton::mouseReleaseEvent(QMouseEvent *e){

//}
